import MySQLdb

conn = MySQLdb.connect(host='47.107.87.249', port=3306, user='cxk', password='123456',
                       db='hrs', charset='utf8')

try:
    with conn.cursor() as cursor:
        affected_rows = cursor.execute(
            'insert into tb_dept value (%s.,%s,%s)',
            (60, '研发3部', '阿联酋')
        )
        if affected_rows == 1:
            print('新增部门成功')
        conn.commit()
except BaseException as ex:
        print(ex)
        conn.rollback()
finally:
    conn.rollback()
